﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Stone_Jumper.Properties;

namespace Stone_Jumper
{
    public partial class MainMenu : Form
    {
        private readonly Dictionary<Button, Bitmap> _buttonFucusDictionary;
        private readonly Dictionary<Button, Bitmap> _buttonNoFucusDictionary;
      
        public MainMenu()
        {
            
            InitializeComponent();
            _buttonFucusDictionary = new Dictionary<Button, Bitmap>()
            {
                {startButton, new Bitmap((Properties.Resources.startFocus), 200, 60)},
                {resumeButton, new Bitmap((Properties.Resources.resumeFocus), 200, 60)},
                {settingsButton, new Bitmap((Properties.Resources.settingsFocus), 200, 60)},
                {exitButton, new Bitmap((Properties.Resources.exitFocus), 200, 60)}
                ,
                {topScoreButton, new Bitmap((Properties.Resources.topScoreFocus), 200, 60)}
            };
            _buttonNoFucusDictionary = new Dictionary<Button, Bitmap>()
            {
                {startButton, new Bitmap((Properties.Resources.startNoFocus), 200, 60)},
                {resumeButton, new Bitmap((Properties.Resources.resumeNoFocus), 200, 60)},
                {settingsButton, new Bitmap((Properties.Resources.settingsNoFocus), 200, 60)},
                {exitButton, new Bitmap((Properties.Resources.exitNoFocus), 200, 60)}
                ,
                {topScoreButton, new Bitmap((Properties.Resources.topScoreNoFocus), 200, 60)}
            };
            foreach (Button button in _buttonNoFucusDictionary.Keys)
            {
                button.BackgroundImage = _buttonNoFucusDictionary[button];
            }
            StartPosition = FormStartPosition.CenterScreen;
            var titleImage =new  Bitmap(Resources.Title,TitleBox.Width,TitleBox.Height);
            titleImage.MakeTransparent();
            TitleBox.Image = titleImage;

          exitButton.PreviewKeyDown+=Exit;
          startButton.PreviewKeyDown += StartGame;
          resumeButton.PreviewKeyDown += ResumeGame;
          settingsButton.PreviewKeyDown += GameSettings;
           
        }

        private void MainMenu_Load(object sender, EventArgs e)
        {
            
            this.TopMost = true;
            this.FormBorderStyle = FormBorderStyle.None;
            Cursor.Hide();
            this.BackgroundImage = Resources.backGroundMainMenu;

        }

        private void ChangeFocus(object sender, EventArgs e)
        {
           
            var button = sender as Button;
            if (button != null)
            {
                    button.BackgroundImage = !button.Focused
                    ? _buttonFucusDictionary[button]
                    : _buttonNoFucusDictionary[button];
            }
            new
                SoundPlayer(Resources.buttonChange).Play();

        }

        private void GameSettings(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.Hide();
                new
               SoundPlayer(Resources.buttonChange).Play();
                new GameSettingsForm(this).Show();
            }
        }

        private void StartGame(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.Hide();
                new
            SoundPlayer(Resources.startGame).Play();
                new Game(this);
            }
        }
        private void ResumeGame(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.Hide();
                new Game(this);
            }
        }
        private void Exit(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                new
                  SoundPlayer(Resources.endGame1).Play();
                Application.Exit();
               
            }
        }

        private void startButton_Click(object sender, EventArgs e)
        {

        }
    }
}
